<%@page import="com.kensure.shike.constant.BusiConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<jsp:include page="base/header.jsp" flush="true"> 
 <jsp:param value="信息内容编辑" name="pageTitle"/>
</jsp:include>
	<script type="text/javascript" charset="utf-8" src="<%=BusiConstant.context%>/utf8-jsp/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=BusiConstant.context%>/utf8-jsp/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="<%=BusiConstant.context%>/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<style>
	.pic{width:180px;height:180px;}
</style>

<body>


<style>
.mainweb{ 
	width:100%; 
	height:100%; 
	overflow:auto; 
} 
.btop{
	position:absolute; 
	top:10px; 
	right:16px; 
	width:100px; 
	height:100px; 
}
</style>

<div style="padding: 15px;" class="mainweb layui-anim layui-anim-upbit">
	
	<fieldset class="layui-elem-field">
		<legend>信息编辑</legend>
		<div class="layui-field-box">
		    <form id="editForm" class="layui-form" lay-filter="form">
			   
			     <div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-inline">
						<input type="text" name="title" style="width:600px;" class="layui-input" value="">
					</div>
				</div>
				
				<div class="layui-form-item" id="chimadiv">			
					<label class="layui-form-label">图片</label>
					<div class="item-con" id="img-con">         	
		                  <img class="pic" style="width:200px;height:100px;" id="picurl" src="<%=BusiConstant.context%>/common/images/no_pic.jpg" onclick="uploadpic(this)">
		              </div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">链接</label>
					<div class="layui-inline">
						<input type="text" name="url" style="width:600px;" class="layui-input" value="">
					</div>
				</div>	
				
				 <div class="layui-form-item" id="fenlei">
					<label class="layui-form-label">分类</label>
			     	
			    </div>	
	
				<div class="layui-form-item">
					<label class="layui-form-label">排序(越小越排前面)</label>
					<div class="layui-inline">
						<input type="text" name='disorder' class="layui-input" value="">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">详情</label>
					<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
				</div>
		        
		    </form>
		 </div>
	</fieldset>		
</div>

 	<div id="dg" class="proll">
		<div class="divroll">
				<button id="btn1" onclick="savebaobei()"  class="layui-btn layui-btn-normal">保存</button>
				
		</div>
	</div>

</body>




<script>
	var ue;	
	$(function(){
		ue = UE.getEditor('editor',{
		    autosave: false,
		    textarea:"content"
		});
	})
	
	function setleimu(){
		var url = getbaseurl("/sys/dictlist.do");
		var data = {typeid:4};
		postsync(url, data, function(data){
			var rows = data.resultData.rows;
			var html = "";
			for(var i=0;rows.length>i;i++){
				var row = rows[i];
				html += "<input name='typeid' type='radio' title='"+row.name+"' value='"+row.code+"'>";
			}
			$("#fenlei").append(html);
		}, null, null);
	}
    setleimu();
    
    var id = getQueryVariable("id");
    
    $(function(){
 	   ue.ready(function() { 
		   //JavaScript代码区域，layui初始化
			layui.use(['element', 'layer', 'form', 'laydate', 'upload'], function(){
				var $ = layui.jquery;
				var element = layui.element;
				var layer = layui.layer;
				var form = layui.form;
				var laydate = layui.laydate,
					upload = layui.upload;	
				
			    if(id){
			    	var url = getbaseurl("/cms/get.do");
			    	var data = {id:id};
			    	postsync(url, data, function(data){
						var row = data.resultData.row;
						row.typeid = row.typeid+"";
						ue.setContent(row.content,false);
						form.val('form',row);
						$("#picurl").attr("src",row.picurl);
						form.render();
					}, null, null);
			    }
			});
 	  	});
	});
	function uploadpic(obj){
		//上传活动主图
		uploadImage(function(p) {
			var rows = p.resultData.rows;
			$.each(rows, function(i, row){
			      $(obj).attr("src",row);
			});
		}, false);
	}
	
	// 保存
	var baocun = false;
	function savebaobei() {
		if (baocun) {
			alert("请勿重复保存");
		}	
		baocun = true;
		var data = formtojson($('#editForm'));
		if(id){
			data.id = id;
		}
		data.picurl = $('#picurl').attr("src");
		
		var url = getbaseurl("/cms/save.do");
		postdo(url, data, function(data){
			alert("保存成功")
			var mylay = parent.layer.getFrameIndex(window.name);
            parent.layer.close(mylay);
            window.parent.doSearch();
		}, null, svcompdo);
	}
	
	function svcompdo(data) {
		baocun = false;
	}
	
     
</script>


</html>